<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <!-- 引入jq -->
    <script src="../../三段/jquery.js"></script>
  </head>
  <body>
    <input type="text" id="test" />
    <div
      id="jieliu"
      style="
        width: 500px;
        height: 300px;
        overflow: auto;
        border: 1px solid #ccc;
      "
    >
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
      <h1>拉屎的徕卡事件流肯德基as肯德基</h1>
    </div>
  </body>
  <script>
    //节流
    function throttle(fn, wait) {
      var pre = Date.now()
      return function () {
        var context = this
        var args = arguments
        var now = Date.now()
        if (now - pre >= wait) {
          fn.apply(context, args)
          pre = Date.now()
        }
      }
    }

    // 定时器方案
    function throttle(fn, wait) {
      var timer = null
      return function () {
        var context = this
        var args = arguments
        if (!timer) {
          timer = setTimeout(function () {
            fn.apply(context, args)
            timer = null
          }, wait)
        }
      }
    }
    function handle() {
      console.log(Math.random())
    }

    $(function () {
      $('#test').on(
        'keyup',
        debounce(function () {
          console.log($(this).val())
        }, 1000)
      )
      $('#jieliu').on(
        'scroll',
        throttle(function () {
          console.log(123123123)
        }, 1000)
      )
    })
  </script>
</html>
